import request from '@/utils/request'

// 登录
export const loginT = (loginData) => {
  const params = new URLSearchParams()
  for (let key in loginData) {
    params.append(key, loginData[key])
  }
  return request.post('/user/login', params)
}

// 注册
export const RegisterT = (registerData) => {
  //借助于UrlSearchParams完成传递
  const params = new URLSearchParams()
  for (let key in registerData) {
    params.append(key, registerData[key])
  }
  return request.post('/user/register', params)
}

//获取用户详细信息
export const userInfoService = () => {
  return request.get('/user/userInfo')
}

//更新用户信息
export const updateUserService = (updateData) => {
  return request.put('/user/update', updateData)
}

//更换头像
export const updateAvatarService = (avatarUrl) => {
  const params = new URLSearchParams()
  params.append('avatarUrl', avatarUrl)
  return request.patch('/user/updateAvatar', params)
}

// 重置密码
export const updatePwdService = (updatePwdData) => {
  const params = new URLSearchParams()
  for (let key in updatePwdData) {
    params.append(key, updatePwdData[key])
  }
  return request.patch('/user/updatePwd', params)
}
